package cn.ziav.rpc.handler;

import cn.ziav.rpc.bean.Page;
import cn.ziav.rpc.bean.User;
import cn.ziav.rpc.server.IMsgHandler;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/** @author Zavi */
public class ListUserMsgHandler implements IMsgHandler<Integer, Page<User>> {

  @Override
  public Page<User> process(Integer pageNo) throws Throwable {
    List<User> userList = new ArrayList<>(15);

    for (int i = 0; i < 15; i++) {
      User user = new User();

      user.setId(i);
      user.setName("Doug Lea" + i);
      user.setSex(1);
      user.setBirthday(LocalDate.of(1968, 12, 8));
      user.setEmail("dong.lea@gmail.com" + i);
      user.setMobile("18612345678" + i);
      user.setAddress("北京市 中关村 中关村大街1号 鼎好大厦 1605" + i);
      user.setIcon("https://www.baidu.com/img/bd_logo1.png" + i);
      user.setStatus(1);
      user.setCreateTime(LocalDateTime.now());
      user.setUpdateTime(user.getCreateTime());

      List<Integer> permissions =
          new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 19, 88, 86, 89, 90, 91, 92));
      user.setPermissions(permissions);

      userList.add(user);
    }

    Page<User> page = new Page<>();
    page.setPageNo(pageNo);
    page.setTotal(1000);
    page.setResult(userList);

    return page;
  }

  @Override
  public int msgId() {
    return MsgId.LIST_USER;
  }
}
